define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'designermanager/designer/index' + location.search,
                    add_url: 'designermanager/designer/add',
                    edit_url: 'designermanager/designer/edit',
                    del_url: 'designermanager/designer/del',
                    multi_url: 'designermanager/designer/multi',
                    check_url: 'designermanager/designer/check',
                    table: 'self_designer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id'),
                            searchable: false
                        },
                        {
                            field: 'real_name',
                            title: __('Real_name')
                        },
                        {
                            field: 'gender',
                            title: __('Gender'),
                            searchList: {
                                "0": __('Gender 0'),
                                "1": __('Gender 1')
                            },
                            formatter: Table.api.formatter.normal,
                            searchable: false
                        },
                        {
                            field: 'job',
                            title: __('职业'),
                            searchable: false
                        },
                        {
                            field: 'age',
                            title: __('Age'),
                            searchable: false
                        },
                        {
                            field: 'years',
                            title: __('Years')
                        },
                        {
                            field: 'company',
                            title: __('Company')
                        },
                        {
                            field: 'qq',
                            title: __('Qq')
                        },
                        {
                            field: 'mobile',
                            title: __('Mobile')
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {
                                "0": __('Status 0'),
                                "1": __('Status 1'),
                                "2": __('Status 2')
                            },
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.buttons,
                            buttons: [
                                {
                                    name: 'refuse',
                                    title: __('审核拒绝'),
                                    classname: 'btn btn-xs btn-primary btn-prompt',
                                    extend: ' data-prompt="2" data-datakey="reason" data-table-id="table" placeholder="请输入原因"',
                                    icon: 'fa fa-times',
                                    url: $.fn.bootstrapTable.defaults.extend.check_url + "?action=refuse",
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh', {});
                                        Layer.alert(ret.msg);
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return row.status == 0;
                                    }
                                },
                                {
                                    name: 'check',
                                    title: __('审核通过'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    icon: 'fa fa-check',
                                    url: $.fn.bootstrapTable.defaults.extend.check_url  + "?action=check",
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh', {});
                                        Layer.alert(ret.msg);
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return row.status == 0;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});